<template>
  <div class="table-wrap">
    <el-table :data="tableData" style="width: 100%" v-bind="tableStyle" >
    <template v-if="tableItem.columns && tableItem.columns.length > 0">
      <el-table-column 
        v-for="(item, index) of tableItem.columns" 
        :key="index" 
        v-bind="{ ...(tableItem.options ? Object.assign(item, tableItem.options) : item) }"
      />
      <el-table-column fixed="right" label="操作" width="120">
      <template #default="scope">
        <el-button link type="primary" size="small" @click="handleEdit(scope.row)">编辑</el-button>
        <el-button link type="primary" size="small" @click="handleDelete(scope.row)">删除</el-button>
        <slot name="buttons" :row="scope.row"></slot>
      </template>
    </el-table-column>
    </template>
  </el-table>
  </div>
</template>

<script setup>
const props = defineProps({
  tableItem: {
    type: Object,
    default: () => ({}),
  },
  tableData: {
    type: Array,
    default: () => ([]),
  },
  tableStyle: {
    type: Object,
    default: () => ({})
  },
});

const emit = defineEmits(['edit', 'delete']);
const handleEdit = (row) => {
  emit('edit', row);
};

const handleDelete = (row) => {
  emit('delete', row);
};
</script>
